package cn.wzvtc.ch12pagesort.repository;

import cn.wzvtc.ch12pagesort.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
    @Query(value = "select *  from User WHERE gender = ?1", nativeQuery = true)
    Page<User> findPageByGender(Integer gender, Pageable page);

    @Query(value = "select u from User u  WHERE u.gender = ?1")
    List<User> findByGenderSort(Integer gender, Sort sort);
}
